找传奇、传世资源到传世资源站!

treegrid自定义控件

8.5玩家评分(1人评分)
下载后可评
介绍 评论 失效链接反馈

/// <summary>
/// 锁定线的颜色,可以自定义,默认为DarkGray
/// </summary>
public Color LockLineColor = Color.DarkGray;
/// <summary>
/// q锁定线的宽度
/// </summary>
public int   LockLineWidth = 1; 

//----------------------------------显示控制-------------------begin
public bool Disp_VLine     = true; //显示列上的线
public bool Disp_HLine     = true; //显示行上的线
public bool Disp_LockLine  = true; //显示锁定线

public bool Disp_TreeHLine     = true; //显示行树上的级次线

//----------------------------------显示控制-------------------end

//------------event----------------
/// <summary>
/// NODE被展开时的事件;行上的树
/// </summary>
public IEvent_NodeExpand     iEvent_RowNodeExpanded = null;
/// <summary>
/// NODE被展开时的事件;列上的树
/// </summary>
public IEvent_NodeExpand     iEvent_ColNodeExpanded = null;
/// <summary>
/// 当前单元格被改变前的事件,相当于TREE中的ONCHANGING;
/// </summary>
public IEvent_RowColChanging iEvent_RowColChanging = null;
/// <summary>
/// 当前单元格被改变后的事件,相当于TREE中的ON_CHANGED;
/// </summary>
public IEvent_RowColChanged  iEvent_RowColChanged = null;

/// <summary>
/// 某一单元的内容即将发生变化时的事件
/// </summary>
public IEvent_CellValueChanging iEvent_CellValueChanging = null;

/// <summary>
/// 某一单元值发生变化后的事件
/// </summary>
public IEvent_CellValueChanged  iEvent_CellValueChanged = null;

//---------event end-------------------
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>var define end -------------------------------------------

internal Graphics dc() { {
// get
if (m_dc == null) {
Rectangle rr = this.workRegion.WorkRect;

if(rr.Width <= 0 || rr.Height <= 0) {
m_bmp = new Bitmap(1,1);
}
else {
m_bmp = new Bitmap(rr.Width,rr.Height); //r.Width,r.Height);
}

m_dc = Graphics.FromImage(m_bmp);//this.CreateGraphics();
//m_dc = this.CreateGraphics();
}

return m_dc;
}

}

internal void ResetDC() {
try {
if(m_dc != null) {
m_dc.Dispose();
}
}
catch {

}
try {
if(m_bmp != null) {
m_bmp.Dispose();
}

}
catch {

}

m_dc = null;
m_bmp = null;
}

/// <summary>
/// 初始化,在显示控件之前调用;
/// </summary>
public void Init() {
this.curPos = new TRCellPos(this);
this.mousePosition_Director = new TRMousePosition(this);

//TREDIT
this.TREDIT = new TREdit(this);
this.TREDIT.SetAdapter(new TREdit_Adapter(this));

//this.TREDIT.TextChanged = new System.EventHandler(this.On_TextChanged);

//-------------------------------------- vTree.IncWnd(1);
// vTree.DrawControl();
// vTree.dc = this.dc();
vTree.m_bVertical = true;
vTree.Indent      = 10;
vTree.defaultDistance = 90;

vTree.ClientRectAll = new Rectangle(0,0,this.ClientRectangle.Width,70);

//vTree.outputDebug       = this.outputDebug;
vTree.RequestPaint         = new event_NotifyPaint(event_TRSoil_RequestPaint);
vTree.On_Notify_Expanded   = new event_NotifyExpanded(event_vTree_NodeExpanded);
//hTree ---------------------------------------------------------
// hTree.dc = this.dc();
hTree.m_bVertical = false;

hTree.ClientRectAll = new Rectangle(0,70,
this.ClientRectangle.Width,
this.ClientRectangle.Height - 70);

//hTree.outputDebug = this.outputDebug;
hTree.RequestPaint = new event_NotifyPaint(event_TRSoil_RequestPaint);
hTree.On_Notify_Expanded   = new event_NotifyExpanded(event_hTree_NodeExpanded);
//-----------SCRollBar-------------------------
hScrollBar.Height = this.hScrollBarHeight;
hScrollBar.Parent = this;
hScrollBar.Visible = true;
hScrollBar.Scroll = new ScrollEventHandler(this.hScrollBar_Scroll);

//----------vScrollBar

vScrollBar.Width  = this.vScrollBarWidth;
vScrollBar.Parent = this;
vScrollBar.Visible = true;

vScrollBar.Scroll = new ScrollEventHandler(this.vScrollBar_Scroll);
//==============all============================
//this.Resize     = new System.EventHandler(this.On_Resize);

this.SizeChanged = new EventHandler(this.ON_SizeChanged);

this.MouseDown = new MouseEventHandler(this.On_MouseDown);
//this.Paint = new PaintEventHandler(this.On_Paint);
this.MouseMove = new MouseEventHandler(this.On_MouseMove);
this.MouseUp   = new System.Windows.Forms.MouseEventHandler(this.On_MouseUp);

this.MouseWheel = new MouseEventHandler(On_MouseWheel);
this.KeyDown   = new System.Windows.Forms.KeyEventHandler(this.On_KeyDown);

}

internal void DrawTextOfTopLeft(Graphics dc) {
Rectangle rect = new Rectangle(workRegion.WorkRect.Location,
new Size(this.hTreeWidth,
workRegion.vTreeRect.Height
));

dc.SetClip(rect);
//shadow effect

dc.DrawLine(Pens.Gray,rect.Right - 1,rect.Top,rect.Right - 1,rect.Bottom);
dc.DrawLine(new Pen(Color.White,0.5F),rect.Right,rect.Top,rect.Right ,rect.Bottom);

StringFormat fmt = new StringFormat();
// fmt.Alignment = StringAlignment.Far;
fmt.LineAlignment = StringAlignment.Center;
// fmt.LineAlignment = StringAlignment.Near;
fmt.FormatFlags = StringFormatFlags.NoWrap;

dc.DrawString(textOfTopLeft,
fontOfTopLeft,
Brushes.Black,
rect,
fmt
);

}

/// <summary>
/// 对控件进行重新绘制
/// </summary>
public void DrawAll() {
//DateTime dt0 = DateTime.Now;

Graphics g = this.CreateGraphics();

this.DrawAll(g);

//GC.Collect(3);

DateTime dt = DateTime.Now;

//--------------ShowEdit------------------
ShowEdit_Smart();

//get focus to make mousewheel event visible
this.Focus();

/*
this.HideEdit();

if (curPos.vTreeNode().readOnly != true)
this.ShowEdit();
if (curPos.hTreeNode().readOnly != true)
this.ShowEdit();
*/

this.Debug("---------DrawAll() ");

}
/// <summary>
/// 对控件进行重新绘制
/// </summary>
public void DrawAll(Graphics g) {
this.ResetDC();

Graphics dc = this.dc();

try {
dc.Clear(Color.White);

//TextOf TopLeft

//-----------------Header

Rectangle rect = new Rectangle(workRegion.WorkRect.Location,
new Size(workRegion.WorkRect.Width,
workRegion.vTreeRect.Height
));

dc.SetClip(rect);

//shadow effect
dc.FillRectangle(new SolidBrush(Color.LightGray),rect);
dc.DrawLine(new Pen(Color.Black,1F),rect.Left,rect.Bottom - 1,rect.Right,rect.Bottom - 1);

//ControlPaint.DrawButton(dc,rect,ButtonState.Normal);

//-------TopLeft--------------------------------------------
DrawTextOfTopLeft(dc);

//-------------vTree----------------------------------------
dc.SetClip(workRegion.vTreeRect);
vTree.DrawControl(dc,this.nodeDrawParam_vTree,this.curPos.vTreeNode());

//-------------hTree---------------------------------------
dc.SetClip(workRegion.hTreeRect);
dc.FillRectangle(Brushes.White,workRegion.hTreeRect);
hTree.DrawControl(dc,this.nodeDrawParam_hTree,this.curPos.hTreeNode());

//cell
dc.SetClip(workRegion.R);
DrawCell(dc);

//-------------Line
dc.SetClip(workRegion.WorkRect);
DrawGridLine(dc);
    
if(this.Disp_LockLine){
DrawLockLine(dc);
}

//------------Stretch--------------------------------------
//Graphics g = this.CreateGraphics();
Rectangle r = this.workRegion.WorkRect;
g.SetClip(r);
g.DrawImageUnscaled(m_bmp,0,0);
}
catch(Exception e) {
MessageBox.Show("DrawAll Error \n\r" e.Message);
}

//show Edit Window
//ShowEdit_Smart();
statusVar.Draw_Count = 1;

if (statusVar.Draw_Count > 100){
GC.Collect();
statusVar.Draw_Count = 0;
}

}

/// <summary>
/// 重新绘制锁定线,一般不需要显式调用
/// </summary>
/// <param name="dc"></param>
public void DrawLockLine(Graphics dc) {
if (!Locked()) return;

Graphics g = dc;
g.SetClip(workRegion.WorkRect);

Rectangle r = vTree.ClientRect_Lock;

Point pt0 = new Point(r.Right,r.Top);
Point pt  = new Point(r.Right,workRegion.WorkRect.Bottom);

g.DrawLine(new Pen(new SolidBrush(LockLineColor),LockLineWidth),pt0,pt);
}

private void On_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e) {
if (!this.Focused) this.Focus();

Point pt = new Point(e.X,e.Y);

SetRegion_R1_R2();

if (this.vTree.ClientRectAll.Contains(pt)){
vTree.On_MouseDown(pt);

On_MouseDown_ResizeCol(pt);
}
else
if (this.hTree.ClientRectAll.Contains(pt)){
if(!hTree.On_MouseDown(pt)){
On_Click_hTree(workRegion.hTreeRect,pt);
}
}
else
if (workRegion.RTopLeft.Contains(pt)){
this.On_MouseDown_ResizeCol(pt);
}
else
if (workRegion.R1.Contains(pt)){
On_Click_R1(workRegion.R1,pt);

mouseInfo.oldPos.X = -1;
mouseInfo.eventID  = TRMouseEvent.None;
}
}

private int Debug_Count = 0;
/// <summary>
/// 用于跟踪
/// </summary>
/// <param name="s"></param>
public void Debug(string s) {
//if (!this.outputDebug.Equals(null))
//this.outputDebug(s);
Debug_Count ;
System.Console.WriteLine("------- " Debug_Count " ---------------  " s);

return;
}

internal Rectangle gridRectX(TRRegionType iRegionType) {
Rectangle r = new Rectangle();
switch (iRegionType) {
case TRRegionType.RTopLeft: {
r = new Rectangle(this.ClientRectangle.Location,
new Size(this.hTreeWidth,
this.vTreeHeight )
);
break;
}

case TRRegionType.WorkRect: {
r = new Rectangle(this.ClientRectangle.Location,
new Size(ClientRectangle.Width - this.vScrollBarWidth,
ClientRectangle.Height - this.hScrollBarHeight
));
break;
}
case TRRegionType.R: {
int iLeft =  this.workRegion.WorkRect.Left this.hTreeWidth;
int iTop  =  this.workRegion.WorkRect.Top this.vTreeHeight;

//old
int iWidth = this.workRegion.WorkRect.Width - this.hTreeWidth ;
int iHeight = this.workRegion.WorkRect.Height - this.vTreeHeight;

r = new Rectangle(iLeft,iTop,iWidth,iHeight);
break;
}

case TRRegionType.R1: {
int iLeft =  this.workRegion.WorkRect.Left this.hTreeWidth;
int iTop  =  this.workRegion.WorkRect.Top;

//??? May be wrong ,  20060816
int iWidth = this.workRegion.WorkRect.Width - this.vScrollBarWidth - this.hTreeWidth;
int iHeight = this.vTreeHeight;

r = new Rectangle(iLeft,iTop,iWidth,iHeight);
break;
}
case TRRegionType.R2: {
int iLeft =  this.workRegion.WorkRect.Left this.hTreeWidth;
int iTop  =  this.workRegion.WorkRect.Top;

//??? May be wrong ,  20060816
int iWidth = this.workRegion.WorkRect.Width - this.vScrollBarWidth - this.hTreeWidth;
int iHeight = this.vTreeHeight;

r = new Rectangle(iLeft,iTop,iWidth,iHeight);
break;
}

case TRRegionType.vTreeRect: {
int iLeft =  this.workRegion.WorkRect.Left this.hTreeWidth;
int iTop  =  this.workRegion.WorkRect.Top;
int iWidth = this.workRegion.WorkRect.Width - this.vScrollBarWidth - this.hTreeWidth;
int iHeight = this.vTreeHeight;

r = new Rectangle(iLeft,iTop,iWidth,iHeight);
break;
}

case TRRegionType.hTreeRect: {
int iLeft =  this.workRegion.WorkRect.Left ;
int iTop  =  this.workRegion.WorkRect.Top this.vTreeHeight;
int iWidth = this.hTreeWidth;
int iHeight = this.workRegion.WorkRect.Height - this.vTreeHeight;

r = new Rectangle(iLeft,iTop,iWidth,iHeight);
break;
}

}
return r;
}

/// <summary>
/// 不般不需要显式调用
/// </summary>
public void SetRect() {
workRegion.SetGridRect(this);

hScrollBar.Bounds =  new Rectangle(0,
workRegion.hTreeRect.Bottom,
workRegion.WorkRect.Width,
hScrollBarHeight);

vScrollBar.Bounds =  new Rectangle(workRegion.WorkRect.Right,
workRegion.WorkRect.Top,
this.vScrollBarWidth,
workRegion.WorkRect.Height );

vTree.ClientRectAll = workRegion.vTreeRect;
vTree.SetRect();

hTree.ClientRectAll = workRegion.hTreeRect;
hTree.SetRect();

//ResetDC();

//vTree.dc = this.dc();
//hTree.dc = this.dc();

this.Set_hScrollBar_Range();
this.Set_vScrollBar_Range();
}

private void On_Resize(object sender, System.EventArgs e) {
//SetRect();
//
//vTree.dc   = this.CreateGraphics();
//
//vTree.Reset();
}

private void ON_SizeChanged(object sender, System.EventArgs e) {
SetRect();  //中间已经RESETDC了

this.DrawAll();
}

private void Set_hScrollBar_Range() {
if(this.Locked()) {
int iMax = vTree.GetVisibleNodeCount(vTree.wndLockList[vTree.wndLockList.count - 1].getNextVisibleNode()) ;// vTree.wndList.count vTree.wndLockList.count;

if (iMax > 0) {
hScrollBar.Maximum = iMax ;
hScrollBar.LargeChange = iMax > 20 ? iMax / 10 : 2;

hScrollBar.Maximum = iMax   hScrollBar.LargeChange;
hScrollBar.Minimum = 0;
}
else {
hScrollBar.Maximum = 0;
hScrollBar.Minimum = 0;
}
}
else{
int iMax = vTree.GetVisibleNodeCount(null) ;

if (iMax > 0) {
hScrollBar.Maximum = iMax;
hScrollBar.LargeChange = iMax > 20 ? iMax / 10 : 1;
hScrollBar.Maximum = iMax   hScrollBar.LargeChange;

hScrollBar.Minimum = 0;
}
else {
hScrollBar.Maximum = 0;
hScrollBar.Minimum = 0;
}
}

}

private void Set_vScrollBar_Range() {
//---------vScrollBar

int iMax_H = hTree.GetVisibleNodeCount(null) ;
if (iMax_H > 0) {
vScrollBar.Maximum      = iMax_H;
vScrollBar.LargeChange  = iMax_H > 20 ? iMax_H / 20 : 5;
vScrollBar.Maximum      = iMax_H  vScrollBar.LargeChange;
vScrollBar.Minimum      = 0;
}
else {
vScrollBar.Maximum = 0;
vScrollBar.Minimum = 0;
}
}

private void hScrollToValue(int iValue) {
if(!this.m_hScroll_CanDo) return;

if (this.Locked()) {
TRNode node = vTree.wndLockList[vTree.wndLockList.count - 1].nextVisibleNode;

vTree.SetAbsScrollPos(node,iValue);
}
else {
TRNode node = vTree.nodes[0];

vTree.SetAbsScrollPos(node,iValue);

}

private void hScrollBar_Scroll(object sender, System.Windows.Forms.ScrollEventArgs e) {
hScrollToValue(e.NewValue);

DrawAll();

}

/// <summary>
/// 控制是否滚动滚动条;
/// </summary>
private bool m_vScroll_CanDo = true;
private bool m_hScroll_CanDo = true;
private void vScrollBar_Scroll(object sender, System.Windows.Forms.ScrollEventArgs e) {
this.vScrollToValue(e.NewValue);
}

public void DrawGridLine_H(Graphics dc) {
#region 
//Graphics g = dc;  //Graphics.FromHdc(m.WParam);
//
//if (hTree.wndList.count == 0) return;
//
//for(int i = 0; i < hTree.wndList.count ; i ) {
//TRNode node = hTree.wndList[i];
//int iLeft = workRegion.WorkRect.Left;
//int iTop  = node.bounds.Top;
//int iWidth = workRegion.WorkRect.Width;
//int iHeight = node.bounds.Height;
//
//Rectangle r = new Rectangle(iLeft,iTop,iWidth,iHeight);
//g.DrawRectangle(Pens.LightGray,r);
//}
#endregion

Graphics g = dc;  //Graphics.FromHdc(m.WParam);

if (hTree.wndList.count == 0) return;

//

//-get Width fixed
int  iWidthFixed   = 0; 
int  iWidthDynamic = 0;

if (vTree.wndLockList.count != 0) {
for(int i = 0; i < vTree.wndLockList.count ; i ) {
TRNode node = vTree.wndLockList[i];

iWidthFixed = node.distance;
}
}

//getWidth Dynamic
if (vTree.wndList.count != 0) {
for(int i = 0; i < vTree.wndList.count ; i ) {
TRNode node = vTree.wndList[i];

iWidthDynamic = node.distance;
}
}

//
int iWidthTotal = iWidthFixed iWidthDynamic;

int iLeft  = workRegion.WorkRect.Left;
int iWidth = iWidthTotal this.hTreeWidth;

if(!this.Disp_TreeHLine){
iLeft  = workRegion.R.Left;
iWidth = iWidthTotal ;
}

//---------draw

for(int i = 0; i < hTree.wndList.count ; i ) {
TRNode node = hTree.wndList[i];
int iTop  = node.bounds.Top;

int iHeight = node.bounds.Height;

Rectangle r = new Rectangle(iLeft,iTop,iWidth,iHeight);
g.DrawRectangle(Pens.LightGray,r);

//draw LastLIne
if(!this.Disp_TreeHLine){
if(i == hTree.wndList.count - 1){
int iLastX1 = r.Right;
int iLastY = r.Bottom;

int iLastX0 = workRegion.WorkRect.Left;

g.DrawLine(Pens.LightGray,iLastX0,iLastY,iLastX1,iLastY);
}
}
}

}

private void DrawGridLine_V(Graphics dc,Color lineColor) {
#region
//Graphics g = dc;  //Graphics.FromHdc(m.WParam);
//
//if (vTree.wndList.count == 0) return;
//
//int iDistance = 2;
//
////Dynamic
//for(int i = 0; i < vTree.wndList.count ; i ) {
//TRNode node = vTree.wndList[i];
//int iLeft = node.bounds.Left;
//int iTop  = workRegion.WorkRect.Top - iDistance;
//int iWidth  = node.bounds.Width;
//int iHeight = workRegion.WorkRect.Height;
//
//Rectangle r = new Rectangle(iLeft,iTop,iWidth,iHeight);
//g.DrawRectangle(new Pen(lineColor),r);
//}
//
////Fixed
//for(int i = 0; i < vTree.wndLockList.count ; i ) {
//TRNode node = vTree.wndLockList[i];
//int iLeft = node.bounds.Left ;
//int iTop  = workRegion.WorkRect.Top - iDistance ;
//int iWidth  = node.bounds.Width;
//int iHeight = workRegion.WorkRect.Height;
//
//Rectangle r = new Rectangle(iLeft,iTop,iWidth,iHeight);
//g.DrawRectangle(Pens.Gray,r);
//}

#endregion

Graphics g = dc;  //Graphics.FromHdc(m.WParam);

if (vTree.wndList.count == 0) return;

int iDistance = 2;

//get HeightTotal
int iHeightTotal = 0;
for(int i = 0; i < hTree.wndList.count ; i ) {
TRNode node   = hTree.wndList[i];
iHeightTotal = node.distance;
}

//Dynamic
for(int i = 0; i < vTree.wndList.count ; i ) {
TRNode node = vTree.wndList[i];
int iLeft   = node.bounds.Left;
int iTop    = workRegion.R.Top - iDistance; //workRegion.WorkRect.Top - iDistance;
int iWidth  = node.bounds.Width;
//int iHeight = workRegion.WorkRect.Height;
int iHeight = iHeightTotal;

Rectangle r = new Rectangle(iLeft,iTop,iWidth,iHeight iDistance);
g.DrawRectangle(new Pen(lineColor),r);
}

//Fixed
for(int i = 0; i < vTree.wndLockList.count ; i ) {
TRNode node = vTree.wndLockList[i];
int iLeft = node.bounds.Left ;
int iTop  = workRegion.R.Top - iDistance ;//workRegion.WorkRect.Top - iDistance ;
int iWidth  = node.bounds.Width;
//int iHeight = workRegion.WorkRect.Height;
int iHeight = iHeightTotal;

Rectangle r = new Rectangle(iLeft,iTop,iWidth,iHeight iDistance);
g.DrawRectangle(Pens.Gray,r);
}

}

private void DrawGridLine(Graphics dc) {
RectangleF clipOld = dc.ClipBounds;

if(this.Disp_HLine){
DrawGridLine_H(dc);
}

//画列头上的效果
dc.SetClip(workRegion.vTreeRect);
DrawGridLine_V_3D(dc);

//
if (this.Disp_VLine){
dc.SetClip(workRegion.R);
DrawGridLine_V(dc,Color.LightGray);
}

dc.SetClip(clipOld);
}

private void DrawGridLine_V_3D(Graphics dc) {
Graphics g = dc;  //Graphics.FromHdc(m.WParam);
g.SetClip(workRegion.vTreeRect);

if (vTree.wndList.count == 0) return;

int iDistance = 2;

//Dynamic
for(int i = 0; i < vTree.wndList.count ; i ) {
TRNode node = vTree.wndList[i];
int iLeft   = node.bounds.Left;
int iTop    = workRegion.WorkRect.Top - iDistance;
int iWidth  = node.bounds.Width;
int iHeight = workRegion.WorkRect.Height;

//Rectangle r = new Rectangle(iLeft,iTop,iWidth,iHeight);
//g.DrawRectangle(new Pen(lineColor),r);
//ControlPaint.DrawBorder3D(g,iLeft,iTop,2,workRegion.vTreeRect.Height 2 ,Border3DStyle.Etched);
g.DrawLine(Pens.Gray,iLeft - 1,iTop,iLeft - 1,iTop iHeight);
g.DrawLine(new Pen(Color.White,0.5F),
iLeft,iTop,
iLeft,iTop iHeight);

//RIGHT MAX
if(i ==   vTree.wndList.count - 1) {

iLeft   = node.bounds.Right  ;
iTop    = workRegion.WorkRect.Top - iDistance;
iWidth  = node.bounds.Width;
iHeight = workRegion.WorkRect.Height;

g.DrawLine(Pens.Gray,iLeft - 1,iTop,iLeft - 1,iTop iHeight);
g.DrawLine(new Pen(Color.White,0.5F),
iLeft,iTop,
iLeft,iTop iHeight);

}

}

//Fixed
for(int i = 0; i < vTree.wndLockList.count ; i ) {
TRNode node = vTree.wndLockList[i];
int iLeft = node.bounds.Left ;
int iTop  = workRegion.WorkRect.Top - iDistance ;
int iWidth  = node.bounds.Width;
int iHeight = workRegion.WorkRect.Height;

//ControlPaint.DrawBorder3D(g,iLeft,iTop,2,workRegion.vTreeRect.Height 2 ,Border3DStyle.Etched);
g.DrawLine(Pens.Gray,iLeft - 1,iTop,iLeft - 1,iTop iHeight);
g.DrawLine(new Pen(Color.White,0.5F),
iLeft,iTop,
iLeft,iTop iHeight);

}

}

private void event_TRSoil_RequestPaint(object obj) {
this.DrawAll();
}

protected override void DefWndProc(ref Message m) {
const int WM_LBUTTONUP = 0x0202;
const int WM_LBUTTONDOWN  = 0x0201;

const int WM_PAINT  = 0x000F;

if(m.Msg == MyMessage.WM_TG_FlushData){
bool b = this.FlushData();

m.Result = new IntPtr(0);

if(!b) m.Result = new IntPtr(-1);

return;
}

base.DefWndProc(ref m);
}

public override bool PreProcessMessage(ref Message msg) {
const int WM_LBUTTONDOWN  = 0x0201;

const int WM_KEYDOWN   = 0X0100;
const int WM_KEYUP     = 0X0101;

if (msg.Msg == WM_KEYDOWN) {
if (msg.WParam.ToInt32() == 9) {
//不进行默认的处理;不能让控件失去焦点,模拟一个向右的键ARROW键
msg.WParam = new IntPtr(0);//new IntPtr(13);
if(this.TREDIT.GetAdapter() != null) {
this.TREDIT.GetAdapter().DoNextCol();
}
return true;
}
else {
base.PreProcessMessage(ref msg);
}

}
else {
base.PreProcessMessage(ref msg);
}

return false;
}

/// <summary>
/// 把编辑时未定的内容刷到控件的数据中
/// </summary>
/// <returns></returns>
public bool FlushData(){
//刷新当前的EDIT窗中的内容到数据结构中;
TRNode rowNode = this.curPos.hTreeNode();
TRNode colNode = this.curPos.vTreeNode();

if(rowNode == null || colNode == null) return true;

bool b = true;
this.curPos.FlushData(ref b);

return b;
}

/// <summary>
/// 显否TR被锁定
/// </summary>
/// <returns></returns>
public bool Locked() {
return (vTree.wndLockList.count > 0);

vTree.Clear();
}

private void SetRegion_R1_R2() {
int iWidthTotal = 0;
for( int i = 0; i < vTree.wndLockList.count; i ) {
TRNode node = vTree.wndLockList[i];

iWidthTotal = node.bounds.Width;
}

int iLeft = workRegion.R.Left;
int iTop  = workRegion.R.Top ;
int iWidth  = iWidthTotal;
int iHeight = workRegion.R.Height;

workRegion.R2 = new Rectangle(iLeft,iTop,iWidth,iHeight);

iLeft = workRegion.R.Left iWidthTotal;
iTop  = workRegion.R.Top;
iWidth = workRegion.R.Width - iWidthTotal;
iHeight = workRegion.R.Height;

workRegion.R1 = new Rectangle(iLeft,iTop,iWidth,iHeight);
}

/// <summary>
/// 从某节点开始锁定到结束节点
/// </summary>
/// <param name="fromNode">开始的NODE</param>
/// <param name="endNode">结束的NODE</param>
public void Lock(TRNode fromNode,TRNode endNode) {
vTree.LockNodeRange(fromNode,endNode);

SetRegion_R1_R2();

TRNode node = vTree.wndLockList[vTree.wndLockList.count - 1].nextVisibleNode;

this.Set_hScrollBar_Range();

this.SetRect();
this.DrawAll();
}

/// <summary>
/// 解除锁定
/// </summary>
public void UnLock() {
if (!Locked()) return;

TRNode node = vTree.wndLockList[0];

vTree.wndLockList.Clear();
vTree.TopNode_Lock = null;

vTree.TopNode = node;

//SetRect();
vTree.SetRect();

vTree.ScanDrawNodeToWnd(vTree.wndList,vTree.TopNode,workRegion.vTreeRect);

hScrollBar.Maximum = hTree.GetVisibleNodeCount(null);

hScrollBar.Value = 0;

this.Set_hScrollBar_Range();

this.DrawAll();
}

/// <summary>
/// 返回鼠标在客户区的位置
/// </summary>
/// <returns></returns>
public Point MousePos() {
return this.PointToClient(Control.MousePosition);
}

private void SetCursor() {
//只有等于-1时,才需要设置光标;
if (mouseInfo.eventID != TRMouseEvent.None) return;

//add 20071217
bool bFromRight = this.mousePosition_Director.FromRight;
//end

Point pt = this.MousePos();

//col fixed0
if (workRegion.R.Contains(pt)) {
this.Cursor = Cursors.Arrow;
}

//col fixed
if (workRegion.vTreeRect.Contains(pt)) {
this.Cursor = Cursors.Arrow;

if (vTree.ClientRect_Lock.Contains(pt)) {
Rectangle tempRect = vTree.ClientRect_Lock;

int iWidth = tempRect.Left;
int iIndex = 0;
int iRectRight = tempRect.Right;
bool bFind = false;

for(int i = 0; i < vTree.wndLockList.count ; i ) {
TRNode node = vTree.wndLockList[i];

int iColWidth = node.distance;
iWidth = iColWidth;
Rectangle r = new Rectangle(iWidth - 5,tempRect.Top,11,tempRect.Height);

if (r.Contains(pt))     { bFind = true  ;break;  }
}

if (bFind) this.Cursor = Cursors.VSplit;
}

if (vTree.ClientRect_Dynamic.Contains(pt)) {
Rectangle tempRect = vTree.ClientRect_Dynamic;

int iWidth = tempRect.Left;
int iIndex = 0;
int iRectRight = tempRect.Right;
bool bFind = false;

TRNode curNode = null;

////add 20071217
TRNode findNode = null;
Stack stk = new Stack();
//end

for(int i = 0; i < vTree.wndList.count ; i ) {
TRNode node = vTree.wndList[i];

int iColWidth = node.distance;
iWidth = iColWidth;
Rectangle r = new Rectangle(iWidth - 5,tempRect.Top,11,tempRect.Height);

//if (iWidth > iRectRight) { iIndex = i - 1;  break;      }
//if (r.Contains(pt))     { bFind = true  ;curNode = node; break;}
//----add 20071217
if (r.Contains(pt)) {   
bFind = true  ;
if(bFromRight) {
stk.Push(node);
findNode = node;
this.Debug("-----find node loop in: "   findNode.ToString());
}
else {
findNode = node; 
break;  
}
}
//end

}

//if (bFind) this.Cursor = Cursors.VSplit;
if (bFind) {
if(bFromRight) {
this.Debug("-----from right -------" );
if(stk.Count > 0) {
TRNode  nodeStack = (TRNode)stk.Pop();
findNode = nodeStack;
}
}

if(findNode.distance_lock){
this.Debug("-----distance_lock " );
this.Cursor = Cursors.NoMoveHoriz;
}
else{
this.Debug("-----*** distance_no_lock " );
this.Cursor = Cursors.VSplit;
}
}

}

}

//---------------topLeft Resize-------------------------------------
if (this.workRegion.RTopLeft.Contains(pt)) {
Rectangle tempRect = new Rectangle(workRegion.RTopLeft.Right - 3,
workRegion.RTopLeft.Top,
7,
workRegion.RTopLeft.Height);
this.Cursor = Cursors.Arrow;

bool bFind = tempRect.Contains(pt);

if(bFind){
if(this.hTreeWidth_lock){
this.Cursor = Cursors.NoMoveHoriz;
}
else{
this.Cursor = Cursors.VSplit;
}
}
}

//col Dynamic
if (workRegion.hTreeRect.Contains(pt)) {
this.Cursor = Cursors.Arrow;
}

}

评论

发表评论必须先登陆, 您可以 登陆 或者 注册新账号 !


在线咨询: 问题反馈
客服QQ:174666394

有问题请留言,看到后及时答复